package fr.uniscol.model;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class Periode implements Serializable {

    public static DateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");
    
	private String libelle = null;
	
	private GregorianCalendar debut = null;
	
	private GregorianCalendar fin = null;

	public Periode() {
	}

	public String getLibelle() {
		return libelle;
	}

	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}

	public GregorianCalendar getDebut() {
		return debut;
	}

	public void setDebut(GregorianCalendar debut) {
		this.debut = debut;
	}

	public GregorianCalendar getFin() {
		return fin;
	}

	public void setFin(GregorianCalendar fin) {
		this.fin = fin;
	}
    
    public String getDebutFormated(){
        if(getDebut() == null){
            return "";
        }
        return DATE_FORMAT.format(getDebut().getTime());
    }
    
    public String getDebutFormated(DateFormat df){
        if(getDebut() == null){
            return "";
        }
        return df.format(getDebut().getTime());
    }
    
    public String getFinFormated(){
        if(getFin() == null){
            return "";
        }
        return DATE_FORMAT.format(getFin().getTime());
    }
    
    public String getFinFormated(DateFormat df){
        if(getFin() == null){
            return "";
        }
        return df.format(getFin().getTime());
    }

    public String getType(){
       if(getDebut() != null && getFin() == null){
           return "D";
       }else if(getDebut() == null && getFin() != null){
           return "F";
       }else if(getDebut() != null && getFin() != null){
           return "I";
       }
       return "";
    }
    
    @Override
    public String toString() {
        String out = "";
        if(getDebut() != null && getFin() == null){
            out = "Depuis le: " + getDebutFormated();
        }else if(getDebut() == null && getFin() != null){
            out = "Jusqu'au: " + getFinFormated();
        }else if(getDebut() != null && getFin() != null){
            out = "Du: " + getDebutFormated() + " au: " + getFinFormated();
        }
        return out;
    }
}
